package com.xielaoban.his1.service.serviceimpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xielaoban.his1.common.ServerResponse;
import com.xielaoban.his1.mappers.DepartmentMapper;
import com.xielaoban.his1.model.Department;
import com.xielaoban.his1.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Service
public class DepartmentImpl implements IDepartmentService {
    //spring依赖注入
    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public ServerResponse add(Department department) {
        departmentMapper.insert(department);
        return ServerResponse.createBySuccess();
    }

    @Override
    public ServerResponse selectAll() {
        List<Department> data = departmentMapper.selectAll();
        return  ServerResponse.createBySuccess(data);
    }

    @Override
    public ServerResponse update(Department department) {
        departmentMapper.update(department);
        return ServerResponse.createBySuccess();
    }

    @Override
    public ServerResponse deleteOneById(Department department) {
        departmentMapper.deleteOneById(department);
        return ServerResponse.createBySuccess();
    }

    //设置参数默认值
    @Override
    public ServerResponse qurryByDeptCodeAndDeptName(String keywords,int pagenum,int pagesize) {
        //使用pagehelper分页插件
        PageHelper.startPage(pagenum,pagesize);//查看第一页，每页显示10条

        List<Department> data = departmentMapper.qurryByDeptCodeAndDeptName(keywords);
        //将查询结果封装到pageinfo当中
        PageInfo resultpage = new PageInfo(data);

        return ServerResponse.createBySuccess(resultpage);
    }
}
